﻿@using DTcms.Common;
@{
    ViewBag.Title = "内容列表";
    List<SelectListItem> moveListItems = ViewBag.moveListItems;
    int channel_id = ViewBag.channel_id;
    DTcms.Model.site_channel model = ViewBag.Channel;
    string prolistview = ViewBag.ProListView;
    List<SelectListItem> propertyList = new List<SelectListItem>(){
        new SelectListItem(){ Text = "所有属性", Value = ""},
        new SelectListItem(){ Text = "待审核", Value = "isLock"},
        new SelectListItem(){ Text = "已审核", Value = "unIsLock"},
        new SelectListItem(){ Text = "可评论", Value = "isMsg"},
        new SelectListItem(){ Text = "置顶", Value = "isTop"},
        new SelectListItem(){ Text = "推荐", Value = "idRed"},
        new SelectListItem(){ Text = "热门", Value = "isHot"},
        new SelectListItem(){ Text = "幻灯片", Value = "isSlide"}
    };
}
@section HeaderContent{
    @if (prolistview == "Img")
    {
        <style type="text/css">
            .layui-form-checkbox[lay-skin=primary] {
                padding-left: 20px !important;
            }
        </style>
    }
    else
    {
        <style type="text/css">
            .tb-img-circle {
                width: 40px;
                height: 40px;
                cursor: zoom-in;
                border-radius: 50%;
                border: 2px solid #dddddd;
            }
        </style>
    }
}
<div class="layui-form">
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="javascript:;">内容列表</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <div class="layui-fluid">
        <div class="layui-card layui-tab">
            <div class="layui-card-body table-tool-mini">
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="menu-list">
                            <div class="layui-inline">
                                <div class="layui-input-inline mr0">
                                    <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                    <i class="layui-icon">&#xe615;</i>搜索
                                </button>
                            </div>
                            <a href="javascript:;" data-type="btnView" data-value="Img" class="layui-btn layui-btn-normal img-view" title="图像列表视图"><i class="iconfont icon-list-img"></i></a>
                            <a href="javascript:;" data-type="btnView" data-value="Txt" class="layui-btn layui-btn-normal txt-view" title="文字列表视图"><i class="iconfont icon-list-txt"></i></a>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group">
                                <a data-type="btnAdd" class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../article/article_edit?action=@DTEnums.ActionEnum.Add&channel_id=@channel_id"><i class="iconfont icon-close1"></i><span> 新增</span></a>
                                <a data-type="btnAudit" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-survey"></i><span> 审核</span></a>
                                <a data-type="btnCheckAll" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-selected"></i><span> 全选</span></a>
                                <a data-type="btnRecycle" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-cut"></i><span> 回收站</span></a>
                                <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i><span> 彻底删除</span></a>
                            </div>
                            <div class="menu-select">
                                <select class="select" name="ddlWXPost" lay-filter="btnWx" url="/webapi/weixinJson" selectValue="" promtion="选择推送的微信..."><option value="">选择推送的微信...</option></select>
                                <select class="select" name="ddlCategoryId" lay-filter="btnSearch" url="/webapi/categoryJson?id=@channel_id" selectValue="" promtion="所有类别..."><option value="">所有类别...</option></select>
                                @Html.DropDownList("ddlProperty", new SelectList(propertyList, "Value", "Text"), new { @lay_filter = "btnSearch" })
                                @Html.DropDownList("ddlMoveId", new SelectList(moveListItems, "Value", "Text"), new { @lay_filter = "btnMoveId" })
                            </div>
                        </div>
                    </div>
                </div>
                @if (prolistview == "Img")
                {
                    <!--图片列表-->
                    <div class="imglist">
                        <ul id="ltable"></ul>
                    </div>
                    <!--/图片列表-->
                }
                else
                {
                    <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                        <thead>
                            <tr>
                                <th lay-data="{checkbox:true}"></th>
                                <th lay-data="{field:'title',templet: '#title'}">标题</th>
                                <th lay-data="{field:'CategoryTitle'}">所属类别</th>
                                <th lay-data="{field:'call_index'}">调用别名</th>
                                <th lay-data="{field:'add_time'}">发布时间</th>
                                <th lay-data="{field:'sort_id',edit: 'text'}">排序</th>
                                <th lay-data="{field:'status',templet: '#switchTpl'}">状态</th>
                                <th lay-data="{templet: '#btnTools'}">属性</th>
                                <th lay-data="{templet: '#barDemo'}">操作</th>
                            </tr>
                        </thead>
                    </table>
                }
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="title">
    {{#  if(d.img_url != ''){ }}
    <img src="{{d.img_url}}" class="tb-img-circle" tb-img alt="" />
    {{#  } }}
    <a href="{{d.link_url}}" target="_blank" class="layui-table-link">{{d.title}}</a>
</script>
<script type="text/html" id="btnTools">
    <div class="btn-tools">
        <a href="javascript:;" class="msg {{ d.is_msg==1?'selected':''}}" title="{{ d.is_msg==1?'取消评论':'设置评论'}}" onclick="setStatus({{d.id}}, 'lbtnIsMsg', this);"><i class="iconfont icon-comment"></i></a>
        <a href="javascript:;" class="top {{ d.is_top==1?'selected':''}}" title="{{ d.is_msg==1?'取消置顶':'设置置顶'}}" onclick="setStatus({{d.id}}, 'lbtnIsTop', this);"><i class="iconfont icon-top"></i></a>
        <a href="javascript:;" class="red {{ d.is_red==1?'selected':''}}" title="{{ d.is_msg==1?'取消推荐':'设置推荐'}}" onclick="setStatus({{d.id}}, 'lbtnIsRed', this);"><i class="iconfont icon-good"></i></a>
        <a href="javascript:;" class="hot {{ d.is_hot==1?'selected':''}}" title="{{ d.is_msg==1?'取消热门':'设置热门'}}" onclick="setStatus({{d.id}}, 'lbtnIsHot', this)"><i class="iconfont icon-hot"></i></a>
        <a href="javascript:;" class="pic {{ d.is_slide==1?'selected':''}}" title="{{ d.is_msg==1?'取消幻灯片':'设置幻灯片'}}" onclick="setStatus({{d.id}}, 'lbtnIsSlide', this);"><i class="iconfont icon-pic"></i></a>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a href="../article/article_edit?action=@DTEnums.ActionEnum.Copy&channel_id=@channel_id&id={{d.id}}" class="layui-btn layui-btn-normal layui-btn-xs"><i class="fa fa-copy"></i> 复制</a>
    <a href="../article/article_edit?action=@DTEnums.ActionEnum.Edit&channel_id=@channel_id&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status" {{ d.status == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="rptList">
    <li>
        <s class="po po_{{d.status}}">状态</s>
        <div class="details {{d.img_url!=''?'':'nopic'}}">
            <div class="check checkall"><input type="checkbox" value="{{d.id}}" lay-skin="primary" /></div>
            {{#  if(d.img_url!=''){ }}
            <div class="pic"><img src="/admin/skin/default/loadimg.gif" data-original="{{d.img_url}}" /></div><i class="absbg"></i>
            {{#  } }}
            <h1><span><a href="{{d.link_url}}" target="_blank">{{d.title}}</a></span></h1>
            <div class="remark">{{d.zhaiyao=''?'暂无内容摘要说明...':d.zhaiyao}}</div>
            <div class="tools">
                <a href="javascript:;" class="msg {{d.is_msg==1?'selected':''}}" title="{{d.is_msg==1?'取消评论':'设置评论'}}" lay-event="status" data-btn="lbtnIsMsg"><i class="iconfont icon-comment"></i></a>
                <a href="javascript:;" class="top {{d.is_top==1?'selected':''}}" title="{{d.is_top==1?'取消置顶':'设置置顶'}}" lay-event="status" data-btn="lbtnIsTop"><i class="iconfont icon-top"></i></a>
                <a href="javascript:;" class="red {{d.is_red==1?'selected':''}}" title="{{d.is_red==1?'取消推荐':'设置推荐'}}" lay-event="status" data-btn="lbtnIsRed"><i class="iconfont icon-good"></i></a>
                <a href="javascript:;" class="hot {{d.is_hot==1?'selected':''}}" title="{{d.is_hot==1?'取消热门':'设置热门'}}" lay-event="status" data-btn="lbtnIsHot"><i class="iconfont icon-hot"></i></a>
                <a href="javascript:;" class="pic {{d.is_slide==1?'selected':''}}" title="{{d.is_slide==1?'取消幻灯片':'设置幻灯片'}}" lay-event="status" data-btn="lbtnIsSlide"><i class="iconfont icon-pic"></i></a>
                <input type="text" class="sort" value="{{d.sort_id}}" onkeypress="return checkNumber(event);" data-id="{{d.id}}"/>
            </div>
            <div class="foot">
                <p class="time">{{d.add_time}}</p>
                <a href="../article/article_edit?action=@DTEnums.ActionEnum.Edit&channel_id=@channel_id&id={{d.id}}"><i class="iconfont icon-pencil1"></i></a>
                <a href="../article/article_edit?action=@DTEnums.ActionEnum.Copy&channel_id=@channel_id&id={{d.id}}"><i class="iconfont icon-copy"></i></a>
            </div>
        </div>
    </li>
</script>
@section Scripts{
    @if (prolistview == "Txt")
    {
        <script type="text/javascript">
            layui.use(['table','cascadeSelect','cmswh'], function () {
                var table = layui.table, form = layui.form, cascadeSelect = layui.cascadeSelect,cmswh=layui.cmswh, $ = layui.jquery;
                cascadeSelect.init('ddlWXPost', false);
                cascadeSelect.init('ddlCategoryId', false);

                cmswh.dataBind('ArticleList?channel_id=@channel_id');
                //监听单元格编辑
                table.on('edit(ltable)', function (obj) {
                    cmswh.request("ArticleFiledSave?channel_id=@channel_id", "POST",{ field: obj.field, value: obj.value, id: obj.data.id });
                });
                //监听状态操作
                form.on('switch(status)', function (obj) {
                    cmswh.request("ArticleSwitch?channel_id=@channel_id", "POST",{ id: this.value, status: obj.elem.checked });
                });
                var active = {
                    btnAudit: function () {
                        cmswh.batOperate('ArticleAudit?channel_id=@channel_id', 'id');
                    },
                    btnCheckAll: function () {
                         if ($(this).text() == " 全选") {
                            $(this).children("span").text(" 取消");
                            $(".layui-table .laytable-cell-checkbox input:enabled").prop("checked", true);
                        } else {
                            $(this).children("span").text(" 全选");
                            $(".layui-table .laytable-cell-checkbox input:enabled").prop("checked", false);
                        }
                        form.render('checkbox');
                    },
                    btnRecycle: function () {
                        cmswh.batOperate('ArticleRecycle?channel_id=@channel_id', 'id');
                    },
                    btnDelete: function () {
                        cmswh.batOperate('ArticleDelete?channel_id=@channel_id', 'id');
                    },
                    btnMoveId: function () {//批量移动
                        var categoryId = $("select[name=ddlMoveId]").val();
                        cmswh.batOperate('ArticleMove?channel_id=@channel_id&category_id='+categoryId, 'id');
                    },
                    btnView: function () {
                        var setView = $(this).data("value");
                        cmswh.request("ArticleView?channel_id=@channel_id", "POST",{ view: setView });
                        setTimeout(function () {
                            location.reload();
                        }, 1500);
                    },
                    btnSearch: function () {
                        table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                    }
                };
                form.on('select(btnSearch)', function (data) {
                    var type = "btnSearch";
                    active[type] ? active[type].call(this) : '';
                });
                form.on('select(btnMoveId)', function (data) {
                    var type = "btnMoveId";
                    active[type] ? active[type].call(this) : '';
                });
                form.on('select(btnWx)', function (data) {
                    cmswh.batOperate('ArticleWx?channel_id=@channel_id&accountId='+data.value, 'id');
                });
                $('.toolbar .layui-btn').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
                /* 点击图片放大 */
                $(document).off('click.tbImg').on('click.tbImg', '[tb-img]', function () {
                    layer.photos({photos: {data: [{src: $(this).attr('src')}]}, shade: .1, closeBtn: true});
                });
                function getcond() {
                    var keyword = $("#txtKeywords").val();
                    var categoryId = $("select[name=ddlCategoryId]").val();
                    var propertyType = $("#ddlProperty").val();
                    var postdata = { keywords: keyword, property: propertyType, category_id: categoryId, channel_id:@channel_id };
                    return postdata;
                }
                window.setStatus= function(id, objId, obj) {
                    $.ajax({
                        url: "ArticleStatus?channel_id=@channel_id",
                        cache: false,
                        type: "POST",
                        dataType: "json",
                        data: { id: id, cmdName: objId},
                        success: function (data) {
                            if (data.status == 1) {
                                layer.msg(data.msg, { icon: 6 });
                                if ($(obj).hasClass("selected")) {
                                    $(obj).removeClass("selected");
                                }
                                else {
                                    $(obj).addClass("selected");
                                }
                            } else {
                                layer.alert(data.msg, { icon: 5 });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert('状态：' + textStatus + '；出错提示：' + errorThrown, { icon: 5 });
                        }
                    });
                }
            });
        </script>
    }
    else
    {
        <script type="text/javascript">
            layui.use(['cascadeSelect','cmswh','lazyload','dataGrid'], function () {
                var form = layui.form, cascadeSelect = layui.cascadeSelect, cmswh = layui.cmswh, dataGrid = layui.dataGrid;

                cascadeSelect.init('ddlWXPost', false);
                cascadeSelect.init('ddlCategoryId', false);

                var ins = dataGrid.render({
                    elem: '#ltable',
                    templet: '#rptList',
                    data: 'ArticleList?isGrid=1',
                    where: getcond(),
                    page: {limit: 14},
                    onToolBarClick: function (obj) {
                        var event = obj.event,data = obj.data,elem = obj.elem;
                        if (event == 'status') {
                            $.ajax({
                                url: "ArticleStatus?channel_id=@channel_id",
                                type: "POST",
                                dataType: "json",
                                data: { id: data.id, cmdName: $(elem).data("btn")},
                                success: function (res) {
                                    if (res.status == 1) {
                                        layer.msg(res.msg, { icon: 6 });
                                        if ($(elem).hasClass("selected")) {
                                            $(elem).removeClass("selected");
                                        }
                                        else {
                                            $(elem).addClass("selected");
                                        }
                                    } else {
                                        layer.alert(res.msg, { icon: 5 });
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.alert('状态：' + textStatus + '；出错提示：' + errorThrown, { icon: 5 });
                                }
                            });
                        }
                    },
                    done: function (dataList, curr, count) {
                        //延迟执行,防止多次触发
                        setTimeout(function () {
                            $(".imglist").ruleLayoutImgList();
                        }, 200);
                        $(".pic img").lazyload({ effect: "fadeIn" });
                        form.render('checkbox');
                        sortChange();
                    }
                });

                var active = {
                    btnAudit: function () {
                        cmswh.batIds('ArticleAudit?channel_id=@channel_id');
                    },
                    btnCheckAll: function () {
                        cmswh.checkAll(this);
                        form.render('checkbox');
                    },
                    btnRecycle: function () {
                        cmswh.batIds('ArticleRecycle?channel_id=@channel_id');
                    },
                    btnDelete: function () {
                        cmswh.batIds('ArticleDelete?channel_id=@channel_id');
                    },
                    btnMoveId: function () {//批量移动
                        var categoryId = $("select[name=ddlMoveId]").val();
                        cmswh.batIds('ArticleMove?channel_id=@channel_id&category_id='+categoryId);
                    },
                    btnView: function () {
                        var setView = $(this).data("value");
                        cmswh.request("ArticleView?channel_id=@channel_id", "POST",{ view: setView });
                        setTimeout(function () {
                            location.reload();
                        }, 1500);
                    },
                    btnSearch: function () {
                        ins.reload({where:getcond()});
                    }
                };
                form.on('select(btnMoveId)', function (data) {
                    var type = "btnMoveId";
                    active[type] ? active[type].call(this) : '';
                });
                form.on('select(btnSearch)', function (data) {
                    var type = "btnSearch";
                    active[type] ? active[type].call(this) : '';
                });
                form.on('select(btnWx)', function (data) {
                    cmswh.batIds('ArticleWx?channel_id=@channel_id&accountId='+data.value);
                });
                $('.toolbar .layui-btn').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
                function sortChange() {
                    $(".sort").change(function () {
                        var obj = $(this);
                        var id = obj.data("id");
                        var sort_id = obj.val();
                        cmswh.request("ArticleFiledSave?channel_id=@channel_id", "POST", { id: id, value: sort_id, field: "sort_id" });
                    })
                }
                function getcond() {
                    var keyword = $("#txtKeywords").val();
                    var categoryId = $("select[name=ddlCategoryId]").val();
                    var propertyType = $("#ddlProperty").val();
                    var postdata = { keywords: keyword, property: propertyType, category_id: categoryId, channel_id:@channel_id };
                    return postdata;
                }
            });
        </script>
    }
}
